<?php
	require ('includes/functions.php');
	(checkSession())? $id=checkSession() : redirect();
	
	$query = "SELECT * FROM posts_table ORDER BY dateCreated DESC LIMIT 0,10";
	$posts = mysql_query($query) or die(mysql_error());
	$numPosts = mysql_num_rows($posts);
	
	
?>
<?php include 'includes/header.php';?>
<?php
	
	$query = "Select * from `user_table` where online = 'true' and userId <> $id" ;
	$onlineUsers = mysql_query($query);
	$numOnlineUsers = mysql_num_rows($onlineUsers);
	
	for($i=1;$i <= $numOnlineUsers; $i++){
		$onlineUser = mysql_fetch_array($onlineUsers);
			echo "<a href=\"javascript:void(0)\" onclick=\"javascript:chatWith('".$onlineUser['firstName']."')\">".$onlineUser['firstName']." ".$onlineUser['lastName']."</a><br/>";
	}
?>
	<div id="columns">				
		<div id="column-1" class="column menu"></div>				
		<div class="blocks">
			<table align="center" class = 'post'>
				<tr>
					<form action="submitPost.php" method="POST" name="postsForm">
					<td>
						<textarea class="input" id="watermark" name="post" style="height:70px" cols="60px"></textarea>
					</td>
				</tr>
				<tr>							
					<td><input type="submit" value="Post"></td>
				</tr>
					</form>
			</table>
			<table width = '80%' align = 'center' class="displayPost"  >
			
			<?php for($i = 1; $i<=$numPosts; $i++ ): ?>
			<?php	
				$post = mysql_fetch_array($posts);
				$posterQuery = "SELECT * FROM user_table WHERE userId = ".$post['userId'];
				$poster = mysql_query($posterQuery);
				$poste = mysql_fetch_array($poster); 
			?>
					<tr>
						<td rowspan = "3" style = 'width:90px;vertical-align:top;' >
							<img src='user_images/<?php echo $poste['url']; ?>' height='80' width='80'/>
						</td>
					</tr>
					<tr>
						<td>
							<a href = "viewProfile.php?id=<?php echo $poste['userId']; ?>"><h2><?php echo $poste['firstName']. " ".$poste['lastName']; ?></h2></a>
						</td>
					</tr>
					<tr>
					<td colspan = '2'>
						<table>
							<tr>
								<td style = 'width:30px;'></td>
								<td><?php echo $post['post']; ?>
								</td>
							</tr>
						</table>
					</td>
					</tr>
					<tr height = '35px'></tr>
				<?php endfor; ?>
			</table>
			</div>
		
		<div id="column-3" class="column sidebar"></div>
<?php include 'includes/footer.php';?>	